//package com.rbac.web.schedule;
//
//import com.rbac.web.model.User;
//import com.rbac.web.service.IUserService;
//import com.rbac.web.service.IUserTokenService;
//import java.time.LocalDateTime;
//import java.util.List;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.redisson.api.RLock;
//import org.redisson.api.RedissonClient;
//import org.springframework.scheduling.annotation.Async;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
///**
// * @author gengaoliu
// */
//@Component
//@RequiredArgsConstructor
//@Slf4j
//public class UserSchedule {
//  static final String KEY = "user";
//  private final RedissonClient redissonClient;
//  private final IUserService userService;
//  private final IUserTokenService tokenService;
//
//  /** 每日四点执行定时任务 查询user表中的所有数据 将所有User放入缓存 */
//  @Async
//  @Scheduled(cron = "0 0 4 * * ?")
//  public void userSchedule() {
//    RLock lock = redissonClient.getLock(KEY);
//    try {
//      if (lock.tryLock()) {
//        log.info("[{}]定时任务开始,开始时间：[{}]", KEY, LocalDateTime.now());
//        this.getAllUserToCache();
//        log.info("[{}]定时任务结束,结束时间：[{}]", KEY, LocalDateTime.now());
//      }
//    } finally {
//      lock.unlock();
//    }
//  }
//
//  public void getAllUserToCache() {
//    List<User> users = userService.selectList();
//    tokenService.saveAllUsers(users);
//  }
//}
